import Vue from "vue";
import Vuex from "vuex";
import Cache from '@/utils/cache'
Vue.use(Vuex);
const debug = process.env.NODE_ENV !== "production";
const state = {
	statusIndex: 0,		// 自定义tabbar状态 0-任务，1-我的
	token: null,
	userInfo: {},
	selectProject: null, 	//	添加司机时候选中的项目
	selectAddress: null, 	//	选中地址
	saveDetail01: null,		//	托运地址
	saveDetail02: null,		//	收货地址
};
const getters = {
	statusIndex: state => state.statusIndex,
	token: state => state.token,
	userInfo: state => state.userInfo || {},
	selectProject: state => state.selectProject || [],
	selectAddress: state => state.selectAddress,
	saveDetail01: state => state.saveDetail01,
	saveDetail02: state => state.saveDetail02,
}
const mutations = {
	//	设置tabbar状态值
	SETSTATUSINDEX(state, option){
		state.statusIndex = option
	},
	LOGIN(state, options) {
		state.token = options.token;
		Cache.set("TOKEN", options.token, 59 * 24 * 60 * 60);
		Cache.set("USERINFO", options.userInfo, 59 * 24 * 60 * 60);
	},
	SAVESELECTPROJECT(state, options) {
		state.selectProject = options
	},
	SELECTADDRESS(state, options) {
		state.selectAddress = options
	},
	SAVEDETAIL01(state, options){
		state.saveDetail01 = options
	},
	SAVEDETAIL02(state, options){
		state.saveDetail02 = options
	}
};
const actions = {
	
};

export default new Vuex.Store({
	state,
	mutations,
	actions,
	getters,
	strict: debug
});
